package com.nave.segundaguerra.servidorecliente.cliente;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.PointF;
import android.util.Log;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.ZoomControls;

import com.nave.segundaguerra.game.CalculoImagem;
import com.nave.segundaguerra.servidorecliente.util.ActivityUtil;
import com.nave.segundaguerra.servidorecliente.util.Const;
import com.nave.segundaguerra.servidorecliente.util.ImageLibrary;
import com.nave.segundaguerra.servidorecliente.util.Protocolo;



public class GeneralCliente extends PlayerCliente{
	 private Bitmap meuBotao;
	 private PointF posBotao = new PointF(100,100);
	 private int larguraDaTela;
	 private int alturaDaTela;
	 private int plusScrollFullScreenX;
	 private int plusScrollFullScreenY;
	 
	 public PointF startLocation = new PointF();
	 public PointF endLocation = new PointF();
	 
	private ZoomControls zoom;
	 
	public GeneralCliente(String nome, PointF position) {
		super(nome, position, "General");
		//Coloquei 'Soldado' para teste apenas. por: Nuno
	}
	@Override
	public void draw(Canvas canvas){
		/*if(!this.getDrawTarget()){
		Log.i("Valor3: ", "false");
		}*/
			//canvas.drawLine(startLocation.x, startLocation.y, endLocation.x, endLocation.y, new Paint());
	}
	
	/*@Override Comentado
	public void CarregarImagem(int larguraTela, int alturaTela){
		this.larguraDaTela = larguraTela;
		this.alturaDaTela = alturaTela;
		this.meuBotao = ImageLibrary.getInstance().getImage("ZoomGeneral");
		this.meuBotao = CalculoImagem.getInstance().RedimensionarImagem(this.meuBotao, (8 * alturaTela) / 100, (8 * larguraTela) / 100);
		this.posBotao = new PointF(larguraTela / 1.1f, alturaTela / 7);
	}*/
	@Override
	public void setStartLocation(PointF point){
		this.startLocation = point;
		Log.i("Log","aqui1");
	}
	@Override
	public void setEndLocation(PointF point){
		this.endLocation = point;
	}
	
	
	// Get Scroll
	public int getScrollFullX(){
		return this.plusScrollFullScreenX;
	}
	public int getScrollFullY(){
		return this.plusScrollFullScreenY;
	}
	
	// Comunicacao Servidor
	@Override
	public void sendPos(PointF pos){
	}
	@Override
	public void sendTiro(Point toque){
		this.getDadosCliente().getCliente().Send(Protocolo.PROTOCOL_ITEM + "," + "MunicaoArma" + "," + toque.x + "," + toque.y);
		Log.i(Const.TAG,"Entrou no general.");
	}
	
	// View Port
	@Override
	public void dirViewPort(Point pnt1, Point pnt2, Point tamCanvas, RelativeLayout container, float scale){
		if(scale == 1){
			this.plusScrollX = pnt1.x - pnt2.x;
			this.plusScrollY = pnt1.y - pnt2.y;
			
			if (!((container.getScrollX() + this.getScrollX()) < 0)) {
				if (container.getScrollX() + ActivityUtil.getDisplayWidth()
						+ this.getScrollX() < tamCanvas.x) {
					container.scrollBy(this.getScrollX(), 0);
				}
			}
	
			if (!((container.getScrollY() + this.getScrollY()) < 0)) {
				if (container.getScrollY() + ActivityUtil.getDisplayHeight()
						+ this.getScrollY() < tamCanvas.y) {
					container.scrollBy(0, this.getScrollY());
				}
			}
		}else{
			this.plusScrollFullScreenX = pnt1.x - pnt2.x;
			this.plusScrollFullScreenY = pnt1.y - pnt2.y;
			
			if (!((container.getScrollX() + this.getScrollFullX()) < 0)) {
				if (container.getScrollX() + ActivityUtil.getDisplayWidth()
						+ this.getScrollFullX() < tamCanvas.x) {
					container.scrollBy(this.getScrollFullX(), 0);
				}
			}
	
			if (!((container.getScrollY() + this.getScrollFullY()) < 0)) {
				if (container.getScrollY() + ActivityUtil.getDisplayHeight()
						+ this.getScrollFullY() < tamCanvas.y) {
					container.scrollBy(0, this.getScrollFullY());
				}
			}
			
		}
	}

	@Override
	public void verificarZoom(float x, float y, int altura, int largura, float scaleChange){
			Log.i("Valores", " X: " + x + " Y: " + y + " alt: " + altura + " larg: " + largura + " Scal: " + scaleChange + " PosX: " + meuBotao.getWidth() + " PosY: " + meuBotao.getHeight());
				if(x >= posBotao.x && x < ( posBotao.x + meuBotao.getWidth()) &&
				   y >= posBotao.y && y < ( posBotao.y + meuBotao.getHeight())){
					Log.i("ACERTOU !", "Acertei a imagem haha");
					Log.i("ACERTOU !", "x: " + largura + " y: " + altura);
//					if(!this.telaCheia){
//					//MapaCliente.getInstance().setImage(altura, largura);
//					scaleChange = 1;
//					this.telaCheia = true;
//					}
//					else{
//						//MapaCliente.getInstance().setImage(ImageLibrary.getInstance().getImage("Cenario").getHeight(),ImageLibrary.getInstance().getImage("Cenario").getWidth());
//						scaleChange = 0.5f;
//						this.telaCheia = false;
//					}
				}
	}
}
